home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / FlightSim / mouseMove.c < prev    next >
C/C++ Source or Header  |  1992-12-11  |  4KB  |  183 lines

  1. #include "flight.h"
  2.  
  3.  
  4. extern    FxVector    fxGrid[GRID_SZ][GRID_SZ];
  5. extern    FxVector    fxGridRot[GRID_SZ][GRID_SZ];
  6. extern    FxVector    fxOriginV;
  7.  
  8. extern    FracThreeMatrx    fracRotatMatrx;
  9. extern    FxThreeMatrx    transpCurrFxRotMatrx;
  10.  
  11. extern    Fract    sinPtOne, cosPtOne, sinPtTwo, cosPtTwo;
  12. extern    Fract    sinNPtOne, cosNPtOne, sinNPtTwo, cosNPtTwo;
  13.  
  14. extern    WindowPtr        theWind;    /*the main window*/
  15.  
  16.  
  17. FxVector    pyramid    = {iToFix(-200), iToFix(-100), iToFix(25)},
  18.             cpyPyramid    = {iToFix(-200), iToFix(-100), iToFix(25)};
  19.  
  20. DoMouseMove(strtClik)
  21. Point    *strtClik;
  22. {
  23. static    int        lookUp[6][6] = 
  24.     {    11,    11,    16,    16,    15,    15,
  25.         11,    12,    13,    13,    14,    15,
  26.         6,    7,    8,    8,    9,    10,
  27.         6,    7,    8,    8,    9,    10,
  28.         0,    3,    4,    4,    5,    2,
  29.         0,    0,    1,    1,    2,    2};
  30.  
  31.     int        hCoord, vCoord;
  32.     Point    clikPt;
  33.  
  34.     clikPt = *strtClik;
  35.  
  36.     while (StillDown())
  37.     {
  38.         hCoord = clikPt.h / 43;
  39.         vCoord = clikPt.v / 43;
  40.  
  41.         SetBack();
  42.         DoMove(lookUp[vCoord][hCoord]);
  43.         GetWind(theWind);
  44.         SetPort(theWind);
  45.         GetMouse(&clikPt);
  46.     }
  47. }
  48.  
  49. DoMove(posCoord)
  50. int        posCoord;
  51. {
  52.  
  53.     register    int    i, j;
  54.     FxVector    tempV, _fxGrid[GRID_SZ][GRID_SZ];
  55.     Point    clikPt;
  56.     FxThreeMatrx    currFxRotMatrx;
  57. static    FxVector    xIncrmnt = {iToFix(stepSize), 0, 0};
  58.  
  59.     switch    (posCoord) {
  60.     case 0:
  61.         FracYRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  62.         FracXRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  63.         break;
  64.     case 1:
  65.         FracYRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  66.         break;
  67.     case 2:
  68.         FracYRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  69.         FracXRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  70.         break;
  71.     case 3:
  72.         FracYRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  73.         FracXRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  74.         break;
  75.     case 4:
  76.         FracYRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  77.         break;
  78.     case 5:
  79.         FracYRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  80.         FracXRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  81.         break;
  82.     case 6:
  83.         FracXRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  84.         break;
  85.     case 7:
  86.         FracXRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  87.         break;
  88.     case 8:
  89.         DoForward();
  90.         break;
  91.     case 9:
  92.         FracXRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  93.         break;
  94.     case 10:
  95.         FracXRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  96.         break;
  97.     case 11:
  98.         FracYRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  99.         FracXRotatMatrx(cosPtTwo, sinPtTwo, fracRotatMatrx);
  100.         break;
  101.     case 12:
  102.         FracYRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  103.         FracXRotatMatrx(cosPtOne, sinPtOne, fracRotatMatrx);
  104.         break;
  105.     case 13:
  106.         FracYRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  107.         break;
  108.     case 14:
  109.         FracXRotatMatrx(cosNPtOne, sinNPtOne, fracRotatMatrx);
  110.         break;
  111.     case 15:
  112.         FracXRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  113.         break;
  114.     case 16:
  115.         FracYRotatMatrx(cosNPtTwo, sinNPtTwo, fracRotatMatrx);
  116.         break;
  117.     }
  118.  
  119.     if (posCoord NEQ 8)
  120.     {
  121.         FractToFixMatrx(fracRotatMatrx, currFxRotMatrx);
  122.         FxTranspMatrx(currFxRotMatrx, transpCurrFxRotMatrx);
  123. DoStep();
  124.  
  125.         for (i = 0; i < GRID_SZ; i++)
  126.             for (j = 0; j < GRID_SZ; j++)
  127.             {
  128.                 FxSubtVector(&fxGrid[i][j], &fxOriginV, &tempV);
  129.                 FxMatrxMul(currFxRotMatrx, &tempV, &_fxGrid[i][j]);
  130.             }
  131. FxSubtVector(&pyramid, &fxOriginV, &tempV);
  132. FxMatrxMul(currFxRotMatrx, &tempV, &cpyPyramid);
  133.  
  134.         EraseRect(&thePort->portRect);
  135.         for (i = 0; i < GRID_SZ; i++)
  136.             FxPlotLine(&_fxGrid[i][0], &_fxGrid[i][GRID_SZ - 1]);
  137.     
  138.         for (j = 0; j < GRID_SZ; j++)
  139.             FxPlotLine(&_fxGrid[0][j], &_fxGrid[GRID_SZ - 1][j]);
  140.         *(FxGridMatrx *)fxGridRot = *(FxGridMatrx *)_fxGrid;    
  141. DrawPyr();
  142.     }
  143. }
  144.  
  145. DoStep()
  146. {
  147. static    FxVector    xIncrmnt = {iToFix(stepSize), 0, 0};
  148.     FxVector    tempV;
  149.  
  150.     FxMatrxMul(transpCurrFxRotMatrx, &xIncrmnt, &tempV);
  151.     FxSubtVector(&fxOriginV, &tempV, &fxOriginV);
  152. }
  153.  
  154. DoForward()
  155. {
  156.     FxVector    tempV;
  157.     register    int    i, j;
  158. static    FxVector    xIncrmnt = {iToFix(stepSize), 0, 0};
  159.  
  160.     FxMatrxMul(transpCurrFxRotMatrx, &xIncrmnt, &tempV);
  161.     FxSubtVector(&fxOriginV, &tempV, &fxOriginV);
  162.     for (i = 0; i < GRID_SZ; i++)
  163.         for (j = 0; j < GRID_SZ; j++)
  164.             fxGridRot[i][j].x += iToFix(stepSize);
  165. cpyPyramid.x += iToFix(stepSize);
  166.  
  167.     EraseRect(&thePort->portRect);
  168.     for (i = 0; i < GRID_SZ; i++)
  169.         FxPlotLine(&fxGridRot[i][0], &fxGridRot[i][GRID_SZ - 1]);
  170.  
  171.     for (j = 0; j < GRID_SZ; j++)
  172.         FxPlotLine(&fxGridRot[0][j], &fxGridRot[GRID_SZ - 1][j]);
  173. DrawPyr();
  174. }
  175.  
  176. DrawPyr()
  177. {
  178.     FxPlotLine(&fxGridRot[0][0], &cpyPyramid);
  179.     FxPlotLine(&fxGridRot[1][0], &cpyPyramid);
  180.     FxPlotLine(&fxGridRot[0][1], &cpyPyramid);
  181.     FxPlotLine(&fxGridRot[1][1], &cpyPyramid);
  182. }
  183.